<?php 
if(!$_POST || ($_POST["module"] == "" || $_POST["ajax"] == ""))
{
	exit;
}

// starting
include("_start.php");

// save log as ajax
\Cyfy\Log :: $filename = "ajax";

// if custom language sent
if($_POST["lg"])
{
    \Cyfy\Language :: set($_POST["lg"]);
}

// if fake url
if($_POST["url"]){
    \Cyfy\Cyfy :: $query = $_POST["url"];
}

// PROCESSING AJAX
$output = Cyfy\Ajax :: process($_POST["module"], $_POST["ajax"]);


if(!$output){
	$output = array("success"=>"false");
}

// make it array
if(!is_array($output)){
  $output = array("text"=>$output, "success" => true);
}

// if no redirecting, give messages
if(!$output["location"])
{
    $output["messages"] = $_SESSION["templateMessages"];
    unset($_SESSION["templateMessages"]);
}

// cleans the output
$contents = ob_get_clean();
if(\Cyfy\Cyfy ::  $debug)
{
	if($contents){
		$output["messages"] .= \Cyfy\Message::Get($contents, \Cyfy\Message::ERROR);
	}

	// MYSQL ERROR
	//if($error){
	//	$output["messages"] .= \Cyfy\Message::Get( \Cyfy\Cyfy :: $mysqli -> error,\Cyfy\Message::ERROR);
	//}

}
// print output
print json_encode($output);


// the end
include("_end.php");


